﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WinFormsApp_OpenFolderAndFile
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            string _FilePath = this.txtFileFullPath.Text.Trim();
            if (File.Exists(_FilePath))
            {
                //打开指定文件
                System.Diagnostics.Process.Start(_FilePath);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string _FilePath = this.txtFileFullPath.Text.Trim();

            //打开指定文件夹选中文件(路径不存在则默认打开并选中我的文档)
            System.Diagnostics.Process.Start("explorer.exe", "/select," + _FilePath);

        }

        private void btnOpenWebSites_Click(object sender, EventArgs e)
        {
            string _Path = txtFileFullPath.Text.Trim();
            if (string.IsNullOrEmpty(_Path))
                _Path = "http://www.baidu.com";
            //在WINFORM中使用IE打开网页
            System.Diagnostics.Process.Start("iexplore.exe", _Path); 
        }

    } 
}

